<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .box1{
      width: 100%;
      height: 30px;
      background-color: green;
      color: white;
      font-weight: 700;
      padding-left: 100px;
      line-height: 30px;
    }
    .box2{
      width: 300px;
      height: 300px;
      border: 2px solid #ccc;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translateX(-50%) translateY(-50%);
      cursor:move;
    }
    .box3{
      width: 100%;
      height: 40px;
      background-color: cadetblue;
      line-height: 40px;
      padding-left: 10px;
      box-sizing: border-box;
    }
    span{
      float: right;
      padding-right: 10px;
      cursor:pointer;
    }
  </style>
</head>
<body>
  <div class="box1">注册信息</div>
  <div class="box2">
    <div class="box3">注册信息，可以拖拽<span>关闭</span></div>
  </div>
  <script>
    var box2 = document.querySelector('.box2');
    var span = document.querySelector('span');
    
    box2.onmousedown = function(e){
      //此段代码为了实现浏览器兼容问题
      e = e || window.event;
      var mouse_x = e.clientX - box2.offsetLeft;
      var mouse_y = e.clientY - box2.offsetTop;
      document.onmousemove = function(e){
        e = e || window.event;
        box2.style.left = e.pageX - mouse_x + 'px';
        box2.style.top = e.pageY - mouse_y + 'px';
      };
    };
    box2.onmouseup = function(){
      document.onmousemove = null;
    };
    span.onclick = function(){
      box2.style.display = 'none';
    };
  </script>
</body>
</html>




